import { input_change,submit_item,delete_item } from "./actionType"
const defaultData = {
    inpVal: '羽毛球',
    list: [
        '篮球',
        '乒乓球'
    ]
}
export default (state = defaultData, action) => {
    if (action.type === input_change) {
        const newState = JSON.parse(JSON.stringify(state))
        newState.inpVal = action.value
        return newState
    }
    //添加
    if (action.type === submit_item) {
        if (state.inpVal.trim()) {
            const newState = JSON.parse(JSON.stringify(state))
            newState.list.push(newState.inpVal)
            newState.inpVal = ''
            return newState
        }

    }
    //删除
    if (action.type === delete_item) {
        const newState = JSON.parse(JSON.stringify(state))
        newState.list.splice(action.index, 1)
        return newState
    }
    return state
}